package com.spgf.controller;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.archtecture.model.exceptions.NegocioException;
import com.spgf.model.entities.Categoria;
import com.spgf.model.rn.CategoriaRN;

public class LancamentoDespesaCadActivity extends Activity {

	private Spinner	spnCategoria;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lancamento_despesa_cad_activity);

		try {
			spnCategoria = (Spinner) findViewById(R.id.spn_despesa_cad_categoria);
			spnCategoria.setAdapter(new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, popularComboCategoria()));
			spnCategoria.setSelection(0, true);
		} catch (NegocioException e) {
			e.printStackTrace();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lancamento_despesa_cad, menu);
		return true;
	}

	private Object[] popularComboCategoria() throws NegocioException {
		return new CategoriaRN(this).findAll(new Categoria()).toArray();
	}

}
